package com.cy.store;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

import javax.servlet.MultipartConfigElement;
import javax.servlet.annotation.MultipartConfig;

@Configuration
@SpringBootApplication
@MapperScan("com.cy.store.mapper") //mapperScan 注解 指定当前项目中的mapper接口的所有mapper文件
public class StoreApplication {

    public static void main(String[] args) {
        SpringApplication.run(StoreApplication.class, args);
    }

    @Bean
    public MultipartConfigElement getMultipartConfigElement(){
        //创建一个配置的工厂对象
        MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();
        //配置创建对象的相关信息
        multipartConfigFactory.setMaxFileSize(DataSize.of(10, DataUnit.MEGABYTES));//设置最大的上传的大小限制
        multipartConfigFactory.setMaxRequestSize(DataSize.of(15,DataUnit.MEGABYTES));//在servlet 中的最大值限制

        //通过工厂类来创建对象
        return  multipartConfigFactory.createMultipartConfig();
    }
}
